package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AlbumAndNewDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumListitemVO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理相册数据相关请求的控制器
 *
 * @author java@cn.tedu
 * @version 0.0.1
 */
@Slf4j
@RestController//相当于拥有@ResponseBody和@Controller的功能
/*
元注解
@ResponseBody
@Controller
*/
@Api(tags="04.相册管理模块")
@RequestMapping("/album")
public class AlbumController {
    @Autowired
    private IAlbumService albumService;
    public AlbumController(){
    log.info("创建控制器:AlbumController");
    }
    //http://localhost:9080/album/add-new
    @ApiOperation("添加相册功能")
    @ApiOperationSupport(order=100)
    @PostMapping("/add-new")
    public JsonResult andNew (@Validated AlbumAndNewDTO albumAndNewDTO){
        log.debug("开始处理请求:{}",albumAndNewDTO);
        albumService.addNew(albumAndNewDTO);
        return JsonResult.ok();
    }
    @ApiOperation("根据id删除相册功能")
    @ApiOperationSupport(order=200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "相册id" , dataType = "long", required = true)
    }
    )
    @PostMapping("/{id:[0-9]+}/delete")
    public String deleteById(@PathVariable Long id){
        log.debug("开始处理删除请求!id={}",id);
        albumService.delete(id);
        return "删除完成!";
    }
    @ApiOperation("查询相册数据")
    @GetMapping("/listablum")
    public JsonResult <List<AlbumListitemVO>> list(){
        List <AlbumListitemVO> albumListitemVOS = albumService.listAlbum();
        return JsonResult.ok(albumListitemVOS);
    }
    @ApiOperation("根据id查询相册详细数据")
    @GetMapping("/{id:[0-9]+}/getablum")
    public JsonResult <AlbumStandardVO> getablum(@PathVariable Long id){
        AlbumStandardVO album = albumService.getAlbum(id);
        return JsonResult.ok(album);
    }
}
